package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class LoginDialog extends JFrame{
	private static final long serialVersionUID = 1L;

	private static final int frame_width  = 400;
	private static final int frame_height = 200;
	
	public LoginDialog(){
		super("Quản Lí Khách Sạn - Đăng Nhập");
		setSize(frame_width, frame_height);
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JLabel inst = new JLabel("Vui lòng đăng nhập để sử dụng chương trình");
		inst.setPreferredSize(new Dimension(frame_width, 30));
		
		
	
		add(inst, BorderLayout.NORTH);
		add(new FieldArea(), BorderLayout.CENTER);
		add(new ButtonBar(), BorderLayout.SOUTH);
		
		
		//setVisible(true);
	}
	class ButtonBar extends JPanel{
		private static final long serialVersionUID = 1L;

		public ButtonBar(){
			setLayout(new FlowLayout(FlowLayout.RIGHT));
			JButton button_login  = new JButton("Đăng nhập");
			JButton button_cancel = new JButton("Hủy bỏ");
			button_login.addActionListener(new LoginHandler());
			button_cancel.addActionListener(new CancelHandler());
			add(button_login); add(button_cancel);
		}
	}
	class FieldArea extends JPanel{
		private static final long serialVersionUID = 1L;

		public FieldArea(){
			JLabel label_user = new JLabel("Tên người dùng: ");
			JLabel label_pass = new JLabel("Mật khẩu: ");
			label_user.setPreferredSize(new Dimension(100, 30));
			label_pass.setPreferredSize(new Dimension(100, 30));
			
			JTextField textfield_user = new JTextField(20);
			JPasswordField textfield_pass = new JPasswordField(20);
			
			add(label_user);   add(textfield_user);
			add(label_pass);   add(textfield_pass);
		}
	}
	class LoginHandler implements ActionListener{
		public void actionPerformed(ActionEvent event){
			LoginDialog.this.dispose();
			new MainView();
		}
	}
	class CancelHandler implements ActionListener{
		public void actionPerformed(ActionEvent event){
			System.exit(0);
		}
	}
}
